<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <title>用户管理</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <link href="../../css/mine.css" type="text/css" rel="stylesheet">

    <script type="text/javascript" src="/js/jquery.js"></script>

    <script type="text/javascript">
        $(function () {
            $("#dept").change(function () {
                var deptId = $(this).val()
                if (deptId == 0) {
                    alert("请选择部门")
                } else {
                    $.ajax({
                        url: "/getRole",
                        data: "deptId=" + deptId,
                        type: "POST",
                        dataType: "JSON",
                        success: function (result) {
                            $("#role")[0].length = 0
                            for (var i = 0; i < result.length; i++) {
                                $("#role")[0].add(new Option(result[i].rname, result[i].roleid))
                            }
                        },
                        error: function () {
                            alert("ajax失败回调函数！")
                        }

                    })
                }
            })
        })
    </script>
</head>

<body>

<div class="div_head">
            <span>
                <span style="float:left">当前位置是：-》资源管理》用户管理</span>
                <span style="float:right;margin-right: 8px;font-weight: bold">
                    <a style="text-decoration: none" href="list.jsp">【返回】</a>
                </span>
            </span>
</div>
<div></div>

<div style="font-size: 13px;margin: 10px 5px">
    <form action="/resource/demo2/insertEmp" method="post">
        <table border="1" width="100%" class="table_a">
            <tr>
                <td width="120px;">用户编号<span style="color:red">*</span>：</td>
                <td><input type="text" readonly name="employeenum" value="201501010"/></td>
            </tr>

            <tr>
                <td>登录账号<span style="color:red">*</span>：</td>

                <td>
                    <input type="text" id="loginname" name="loginname" value="zhangsan"/><span></span>
                </td>

            </tr>

            <tr>
                <td>用户姓名<span style="color:red">*</span>：</td>
                <td>
                    <input type="text" name="username" value="张三"/></td>
            </tr>
            <tr>
                <td>密码<span style="color:red">*</span>：</td>
                <td>
                    <input type="text" name="loginpassword" value="......"/>
                </td>
            </tr>
            <tr>
                <td>所属部门<span style="color:red">*</span>：</td>
                <td>
                    <select id="dept" name="deptid">
                        <option value="0">--请选择--</option>
                        <c:forEach items="${deptList}" var="dept">
                            <option value="${dept.deptid}">${dept.deptname}</option>
                        </c:forEach>
                    </select>
                </td>
            </tr>
            <tr>
                <td>所属职位<span style="color:red">*</span>：</td>
                <td>

                    <select id="role" name="roleid">
                        <option value="0">--请选择--</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>身份证<span style="color:red">*</span>：</td>
                <td>
                    <input type="text" name="idcaid" value="372902198708084567"/>
                </td>
            </tr>
            <tr>
                <td>联系电话<span style="color:red">*</span>：</td>
                <td>
                    <input type="text" name="telphone" value="17718181920"/>
                </td>
            </tr>
            <tr>
                <td>邮箱<span style="color:red">*</span>：</td>
                <td>
                    <input type="text" name="email" value="AAA@163.com"/>
                </td>
            </tr>
            <tr>
                <td>联系地址：</td>
                <td>
                    <input type="text" name="address" value="海淀区软件园孵化器"/>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <input type="submit" value="添加">
                    <input type="reset" value="清空">
                </td>
            </tr>
        </table>
    </form>
</div>
</body>
<script type="text/javascript">
    $("[name=loginname]").blur(function () {
        var loginname = $(this).val()
        if(loginname==null){
            alert("请填写登录名！")
        }else{
            $.ajax({
                url:"/resource/demo2/checkLoginName",
                data:"loginname="+loginname,
                type:"POST",
                dataType:"JSON",
                success:function (result) {
                    if(result.code==0){
                        $("#loginname").next().html("用户名可用").css("color","green")
                    }else{
                        $("#loginname").next().html("用户名已经被使用").css("color","red")
                    }
                },
                error:function () {
                    alert("这是ajax失败的回调函数")
                }
            })
        }
    })
</script>
</html>